//
//  GHGoodDetailView.m
//  GodHorses
//
//  Created by Mac on 2017/11/18.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHGoodDetailView.h"
@interface GHGoodDetailView()
@property(nonatomic, strong) STLabel                     *titleLable;
@property(nonatomic, strong) STLabel                     *priceLable;
@property(nonatomic, strong) STLabel                     *originPriceLable;
@property(nonatomic, strong) STLabel                     *desLable;
@property(nonatomic, strong) STLabel                     *numLable;//月消和库存
@property(nonatomic, strong) STLabel                     *cuxiaoLable;//促销
@property(nonatomic, strong) UIView                      *cuxiaoView;//促销白色view 会随动
@property(nonatomic, strong) UIView                      *bootomView;//无数据view 从选择产品开始
@end
@implementation GHGoodDetailView

#pragma mark --subView
- (void)configSubView{
    self.backgroundColor = [UIColor clearColor];
    
    UIView * clearView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, GHIconHeaderHeight)];
    clearView.backgroundColor = [UIColor clearColor];
    [self addSubview:clearView];
    
    UIView * grayView = [[UIView alloc] initWithFrame:CGRectMake(0, clearView.st_bottom, UIScreenWidth, GHIconHeaderHeight)];
    grayView.backgroundColor = GH_backgroundColor;
    [self addSubview:grayView];
    
    //--------------------------第一部分
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, GHIconHeaderHeight)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [grayView addSubview:whiteView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 40)
                                                     text:@"-------"
                                                textColor:GH_firstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    self.titleLable = titleLable;
    self.titleLable.numberOfLines = 0;//最多2行，不在适配
    [whiteView addSubview:self.titleLable];
    
    self.priceLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.titleLable.bottom+ 3, 120, 18)
                                                     text:@"-----"
                                                textColor:GH_redColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];

    [whiteView addSubview:self.priceLable];
    
    self.originPriceLable = [[STLabel alloc] initWithFrame:CGRectMake(self.priceLable.st_right + 3, 0, 120, 18)
                                                text:@"-----"
                                           textColor:GH_secendTextColor
                                                font:15
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    self.originPriceLable.centerY = self.priceLable.centerY;
    [whiteView addSubview:self.originPriceLable];
    
    STButton * baoyouButton = [[STButton alloc] initWithFrame:CGRectMake(10, self.priceLable.st_bottom + 10, 45, 20)
                                                     title:@"包邮"
                                                titleColor:GH_YellowBackGroundColor
                                                 titleFont:14
                                              cornerRadius:3
                                           backgroundColor:GH_BlackBackGroundColor
                                           backgroundImage:nil
                                                     image:nil];
    baoyouButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [whiteView addSubview:baoyouButton];
    
    self.desLable = [[STLabel alloc] initWithFrame:CGRectMake(10 + baoyouButton.st_right, baoyouButton.st_top, UIScreenWidth - baoyouButton.st_right - 20, 20)
                                                text:@"单笔订单满100元包邮"
                                           textColor:GH_firstTextColor
                                                font:16
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    
    [whiteView addSubview:self.desLable];
    
    self.numLable = [[STLabel alloc] initWithFrame:CGRectMake(10 , self.desLable.st_bottom + 15, UIScreenWidth  - 20, 15)
                                              text:@"--------"
                                         textColor:GH_secendTextColor
                                              font:13
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    
    [whiteView addSubview:self.numLable];
    
    whiteView.height = self.numLable.st_bottom + 10;
    
    //第二个部分
    self.cuxiaoView = [[UIView alloc] initWithFrame:CGRectMake(0, whiteView.st_bottom + 10, UIScreenWidth, 50)];
    self.cuxiaoView.backgroundColor = [UIColor whiteColor];
    [grayView addSubview:self.cuxiaoView];
    STLabel * cuxiaoLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, 40, 50)
                                                     text:@"促销"
                                                textColor:GH_YellowBackGroundColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self.cuxiaoView addSubview:cuxiaoLable];
    self.cuxiaoLable = [[STLabel alloc] initWithFrame:CGRectMake(10 + cuxiaoLable.st_right, 0, UIScreenWidth - 20 - cuxiaoLable.st_right , 50)
                                                      text:@"满2752元，送价值999的水券一张"
                                                 textColor:GH_secendTextColor
                                                      font:13
                                               isSizetoFit:NO
                                             textAlignment:NSTextAlignmentLeft];
    self.cuxiaoLable.numberOfLines = 0;
    [self.cuxiaoView addSubview:self.cuxiaoLable];
    [self.cuxiaoView st_showBottomShadow];
    
    //无数据view
    self.bootomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.cuxiaoView.st_bottom  +10, UIScreenWidth, 100)];
    self.bootomView.backgroundColor = [UIColor whiteColor];
    [grayView addSubview:self.bootomView];
    
    //请选择产品规格及数量
    __weak typeof(self) weakSelf =  self;
    STButton * typeButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 50)
                                                     title:@"请选择产品规及数量"
                                                titleColor:GH_firstTextColor
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:nil];
    typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [typeButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedTypeButton:sender];
    }];
    [self.bootomView addSubview:typeButton];
    //灰色
    UIView * bootomGrayView = [[UIView alloc] initWithFrame:CGRectMake(0, typeButton.st_bottom, UIScreenWidth, 10)];
    bootomGrayView.backgroundColor = GH_backgroundColor;
    [self.bootomView addSubview:bootomGrayView];
    
    STButton * iconButton = [[STButton alloc] initWithFrame:CGRectMake(10, bootomGrayView.st_bottom + 10, UIScreenWidth - 20, 44)
                                                     title:@"神马国际"
                                                titleColor:GH_firstTextColor
                                                 titleFont:16
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"logo"]];
    iconButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.bootomView addSubview:iconButton];
    STLabel * bootomLable = [[STLabel alloc] initWithFrame:CGRectMake(10, iconButton.st_bottom, UIScreenWidth - 20, 100)
                                                     text:@"        人饮用后，由胃肠中小肠绒毛柱状上皮细胞的腔面膜吸收，而后进入人体血液，其吸收利用的速度比人由呼吸系统获得的氧要快10倍左右;作用与功效：可以迅速补氧、恢复体力、平衡身体内环境，全面启动自愈康复机制，具体表现为代谢修复、免疫调节、消除炎症、改善过敏体质、防止细胞突变、促进组织修复、抗衰老美容养颜等功效。"
                                                textColor:GH_secendTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    bootomLable.height = [bootomLable.text st_heigthWithwidth:UIScreenWidth - 20 font:13] + 10;
    [self.bootomView addSubview:bootomLable];
    
    self.bootomView.height = bootomLable.st_bottom ;
    grayView.st_height = self.bootomView.bottom;
    self.st_height = grayView.bottom;
}
- (void)setGoodModel:(GHGoodModel *)goodModel{
    _goodModel = goodModel;
    
    self.titleLable.text = goodModel.g_name;
    
    self.priceLable.text = [NSString stringWithFormat:@"￥%@",goodModel.i_price];
    [NSString lableAutoAdjustWitdhWithLabel:self.priceLable];
    self.originPriceLable.st_left = self.priceLable.st_right + 5;
    
    self.originPriceLable.text = [NSString stringWithFormat:@"￥%@",goodModel.m_price];
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:self.originPriceLable.text attributes:attribtDic];
    self.originPriceLable.attributedText = attribtStr;
    
    self.numLable.text = [NSString stringWithFormat:@"销量%@笔      库存%@件",goodModel.g_tosale,goodModel.g_num];
    
}
#pragma mark --Action Method
- (void)onSelectedTypeButton:(UIButton*)sender{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(goodDetailView:onSelectedProductNumButton:)]) {
        [self.delegate goodDetailView:self onSelectedProductNumButton:sender];
    }
}
@end
